﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Homework_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                button1.Text = "请先输入数值！";
            }
            else
            {
                switch (comboBox1.SelectedIndex)
                {
                    case 0://圆形
                        Circel circel = new Circel(double.Parse(textBox1.Text));
                        if (!circel.islegal) button1.Text = "输入的图形不合法!";
                        else button1.Text = "合法!"+circel.showInfo();
                        break;
                    case 1://正方形
                        Square square = new Square(double.Parse(textBox1.Text));
                        if (!square.islegal) button1.Text = "输入的图形不合法!";
                        else button1.Text = "合法!"+square.showInfo();
                        break;
                    case 2://长方形
                        if (textBox2.Text == "") button1.Text = "请先输入数值！";
                        else
                        {
                            Oblong oblong = new Oblong(double.Parse(textBox1.Text), double.Parse(textBox2.Text));
                            if (!oblong.islegal) button1.Text = "输入的图形不合法!";
                            else button1.Text = "合法!"+oblong.showInfo();
                        }
                        break;
                    default:
                        button1.Text = "请先选择图形！";
                        break;
                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    label4.Text = "输入半径：";
                    label5.Text = "";
                    textBox2.Enabled = false;
                    break;
                case 1:
                    label4.Text = "输入边长：";
                    label5.Text = "";
                    textBox2.Enabled = false;
                    break;
                case 2:
                    label4.Text = "输入长度：";
                    label5.Text = "输入宽度：";
                    textBox2.Enabled = true;
                    break;
                default:
                    break;
            }
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            ShapeFactory shapeFactory = new ShapeFactory();
            button1.Text = shapeFactory.drawShapes(int.Parse(textBox3.Text));
        }
    }
}
